home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
701-725
/
723
/
printerctrl
/
source
/
printerctrl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-18
|
29KB
|
1,585 lines
// ------------------------------------------------------------------------
//
// Printer Controller v1.00 (25.07.92)
//
// ------------------------------------------------------------------------
//
// Source: Amiga SAS/Lattice C 5.10b
// Written by: Paul Miskovsky, Toronto, Canada
//
// UUCP: paul.miskovsky@canrem.com
//
// Distributed as UnEmploymentWare (FreeWare), 1992
//
// ------------------------------------------------------------------------
// ---/ Revision History /-------------------------------------------------
//
// Compile Options: LC -b1 -cfist -v -y -m0 -d0 -O <filename[.c]>
//
// Linker Options: LIB:cback.o+<filename.o>+LIB:lreqglue.o
// TO <filename> LIB LIB:lc.lib+LIB:amiga.lib SC SD ND
//
// Debug Testing: ENFORCER: Not Tested - no MMU :(
// MUNGWALL: PASSED
// MEMWATCH: PASSED
//
// Enviroment: Amiga A1000 (68010) w/512k + 1Meg Insider + A590w/2Meg
// 20M Western Digital + 52M Quantum LPS + 44M SyQuest SQ555
//
// AmigaDOS 1.3.2 (Kick 34.5 Work 34.34) - Development
// AmigaDOS 2.04 (Kick 37.175 Work 37.67) - Testing
//
// SAS/Lattice C 5.10b + CygnusEd Professional 2.12
//
//
// req.library © 1988/1989/1990 reserved by Colin Fox and Bruce Dawson
//
//
// July 25, 1992 - v1.00 First release.
//
//
// ---/ Includes /----------------------------------------------------------
#include <clib/intuition_protos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <intuition/intuitionbase.h>
#include <devices/parallel.h>
#include <devices/printer.h>
#include <exec/exec.h>
#include <dos.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <libraries/reqbase.h>
#include <proto/req.h>
// ---/ Defines /-----------------------------------------------------------
const int UNIT_NUMBER = 0;
#define GLNODEFAULTB 0
#define DSIZE 130
#define FCHARS 30
#define PRINT 26
#define STAT 25
#define EXIT 24
#define LINE 23
#define HELP 22
#define CMD 21
#define HEX 20
#define BELL 19
#define SKIP 18
#define JUST 17
#define PROP 16
#define RLF 15
#define LF 14
#define TOF 13
#define DOUB 12
#define SHAD 11
#define ENLRG 10
#define UNDER 9
#define ITAL 8
#define BOLD 7
#define FELITE 6
#define FPICA 5
#define FNORM 4
#define NLQ 3
#define DRFT 2
#define RST 1
// ---/ Version /-----------------------------------------------------------
UBYTE *VersionTag = "\0$VER: PrinterCTRL v1.00 (25.07.92)";
// ---/ Custom Function Prototypes /----------------------------------------
void Open_All( void );
void Close_All( LONG, STRPTR );
void Menu_Analysis( SHORT, SHORT, SHORT );
void RAW_Analysis( USHORT,USHORT );
void Gadget_Analysis( USHORT );
LONG SetupPrinter( void );
LONG OpenPrinter( union printerIO * );
void ClosePrinter( union printerIO *);
void DeletePrtReq( union printerIO * );
LONG PrintPrtCommand( union printerIO *,LONG, UBYTE, UBYTE, UBYTE, UBYTE );
LONG PrintPrtESCCommand( union printerIO *, UBYTE * );
LONG PrintPrtRawString( union printerIO *, STRPTR );
LONG PrintDevCommand( union printerIO *, UWORD );
UBYTE * GetNewWindowTitle( void );
void CenterWindow( struct NewWindow * );
STRPTR MakeFileRequester( struct ReqFileRequester * );
LONG ReqGetLong( struct GetLongStruct * );
LONG NewReqGetString( struct GetStringStruct * );
void ReqShowText( void );
LONG PrintFile( union printerIO *, STRPTR );
LONG SetUpParallel( void );
LONG OpenParallel( void );
void CloseParallel( void );
LONG StatusParallel( struct IOExtPar *, struct IntuiText * );
// ---/ Function Prototypes /-----------------------------------------------
void _main( char * );
union printerIO * CreateExtIO( struct MsgPort *, USHORT );
void DeleteExtIO( struct IORequest * );
struct MsgPort * CreatePort( STRPTR, USHORT );
void DeletePort( struct MsgPort * );
union printerIO * CreatePrtReq( void );
void SimpleRequest( STRPTR,... );
BOOL GetLong( struct GetLongStruct * );
// ---/ Global Structures and Variables /-----------------------------------
struct IntuitionBase *IntuitionBase = NULL;
struct GfxBase *GfxBase = NULL;
struct ReqLib *ReqBase = NULL;
struct Window *mywin1 = NULL;
struct RastPort *rp = NULL;
struct Gadget *GadgetIAddress = NULL;
struct MsgPort *winport = NULL;
struct MsgPort *prtport = NULL;
union printerIO *printerReq;
struct MsgPort *ParallelMP = NULL;
struct IOExtPar *ParallelIO = NULL;
struct ReqFileRequester filereq;
struct GetLongStruct getlong;
struct GetStringStruct getnewstring;
struct TRStructure textreq;
struct IntuiText status;
UBYTE titlearray[40];
LONG numbers[10];
LONG result;
LONG ParallelError;
LONG PrinterError;
union printerIO
{
struct IOStdReq ios;
struct IODRPReq iodrp;
struct IOPrtCmdReq iopc;
};
// ---/ Resident Variables (cback.o) /--------------------------------------
LONG _stack = 4000L;
char *_procname = "PrinterCTRL";
LONG _priority = 0L;
LONG _BackGroundIO = 0L;
// ---/ Power Windows Generated Source /------------------------------------
SHORT BorderVectors1[] = {
0,0,
42,0,
42,10,
0,10,
0,0
};
struct Border Border1 = {
-1,-1,
1,0,JAM1,
5,
BorderVectors1,
NULL
};
SHORT BorderVectors2[] = {
0,0,
363,0,
363,10,
0,10,
0,0
};
struct Border Border2 = {
-1,-1,
1,0,JAM1,
5,
BorderVectors2,
NULL
};
struct TextAttr TOPAZ80 = {
(STRPTR)"topaz.font",
TOPAZ_EIGHTY,0,0
};
struct IntuiText IText0 = {
3,0,JAM1,
100,1,
&TOPAZ80,
"SEND FILE TO PRINTER",
NULL
};
struct Gadget Gadget26 = {
NULL,
6,60,
362,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border2,
NULL,
&IText0,
NULL,
NULL,
26,
NULL
};
struct Gadget Gadget25 = {
&Gadget26,
6,48,
362,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border2,
NULL,
NULL,
NULL,
NULL,
25,
NULL
};
struct IntuiText IText1 = {
3,0,JAM1,
5,1,
&TOPAZ80,
"EXIT",
NULL
};
struct Gadget Gadget24 = {
&Gadget25,
327,36,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText1,
NULL,
NULL,
24,
NULL
};
struct IntuiText IText2 = {
1,0,JAM1,
5,1,
&TOPAZ80,
"LINE",
NULL
};
struct Gadget Gadget23 = {
&Gadget24,
327,24,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText2,
NULL,
NULL,
23,
NULL
};
struct IntuiText IText3 = {
2,0,JAM1,
5,1,
&TOPAZ80,
"HELP",
NULL
};
struct Gadget Gadget22 = {
&Gadget23,
327,12,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText3,
NULL,
NULL,
22,
NULL
};
struct IntuiText IText4 = {
1,0,JAM1,
9,1,
&TOPAZ80,
"CMD",
NULL
};
struct Gadget Gadget21 = {
&Gadget22,
282,36,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText4,
NULL,
NULL,
21,
NULL
};
struct IntuiText IText5 = {
1,0,JAM1,
9,1,
&TOPAZ80,
"HEX",
NULL
};
struct Gadget Gadget20 = {
&Gadget21,
282,24,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText5,
NULL,
NULL,
20,
NULL
};
struct IntuiText IText6 = {
1,0,JAM1,
5,1,
&TOPAZ80,
"BELL",
NULL
};
struct Gadget Gadget19 = {
&Gadget20,
282,12,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText6,
NULL,
NULL,
19,
NULL
};
struct IntuiText IText7 = {
3,0,JAM1,
5,1,
&TOPAZ80,
"SKIP",
NULL
};
struct Gadget Gadget18 = {
&Gadget19,
236,36,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText7,
NULL,
NULL,
18,
NULL
};
struct IntuiText IText8 = {
3,0,JAM1,
5,1,
&TOPAZ80,
"JUST",
NULL
};
struct Gadget Gadget17 = {
&Gadget18,
236,24,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText8,
NULL,
NULL,
17,
NULL
};
struct IntuiText IText9 = {
3,0,JAM1,
5,1,
&TOPAZ80,
"PROP",
NULL
};
struct Gadget Gadget16 = {
&Gadget17,
236,12,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText9,
NULL,
NULL,
16,
NULL
};
struct IntuiText IText10 = {
1,0,JAM1,
9,1,
&TOPAZ80,
"RLF",
NULL
};
struct Gadget Gadget15 = {
&Gadget16,
190,36,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText10,
NULL,
NULL,
15,
NULL
};
struct IntuiText IText11 = {
1,0,JAM1,
5,1,
&TOPAZ80,
" LF",
NULL
};
struct Gadget Gadget14 = {
&Gadget15,
190,24,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText11,
NULL,
NULL,
14,
NULL
};
struct IntuiText IText12 = {
1,0,JAM1,
8,1,
&TOPAZ80,
"TOF",
NULL
};
struct Gadget Gadget13 = {
&Gadget14,
190,12,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText12,
NULL,
NULL,
13,
NULL
};
struct IntuiText IText13 = {
3,0,JAM1,
5,1,
NULL,
"DOUB",
NULL
};
struct Gadget Gadget12 = {
&Gadget13,
144,36,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText13,
NULL,
NULL,
12,
NULL
};
struct IntuiText IText14 = {
3,0,JAM1,
5,1,
&TOPAZ80,
"SHAD",
NULL
};
struct Gadget Gadget11 = {
&Gadget12,
144,24,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText14,
NULL,
NULL,
11,
NULL
};
struct IntuiText IText15 = {
3,0,JAM1,
1,1,
&TOPAZ80,
"ENLRG",
NULL
};
struct Gadget Gadget10 = {
&Gadget11,
144,12,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText15,
NULL,
NULL,
10,
NULL
};
struct IntuiText IText16 = {
3,0,JAM1,
0,1,
NULL,
"UNDER",
NULL
};
struct Gadget Gadget9 = {
&Gadget10,
98,36,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText16,
NULL,
NULL,
9,
NULL
};
struct IntuiText IText17 = {
3,0,JAM1,
5,1,
&TOPAZ80,
"ITAL",
NULL
};
struct Gadget Gadget8 = {
&Gadget9,
98,24,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText17,
NULL,
NULL,
8,
NULL
};
struct IntuiText IText18 = {
3,0,JAM1,
5,1,
&TOPAZ80,
"BOLD",
NULL
};
struct Gadget Gadget7 = {
&Gadget8,
98,12,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText18,
NULL,
NULL,
7,
NULL
};
struct IntuiText IText19 = {
3,0,JAM1,
1,1,
NULL,
"ELITE",
NULL
};
struct Gadget Gadget6 = {
&Gadget7,
52,36,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText19,
NULL,
NULL,
6,
NULL
};
struct IntuiText IText20 = {
3,0,JAM1,
5,1,
&TOPAZ80,
"PICA",
NULL
};
struct Gadget Gadget5 = {
&Gadget6,
52,24,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText20,
NULL,
NULL,
5,
NULL
};
struct IntuiText IText21 = {
3,0,JAM1,
5,1,
&TOPAZ80,
"NORM",
NULL
};
struct Gadget Gadget4 = {
&Gadget5,
52,12,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText21,
NULL,
NULL,
4,
NULL
};
struct IntuiText IText22 = {
2,0,JAM1,
9,1,
NULL,
"NLQ",
NULL
};
struct Gadget Gadget3 = {
&Gadget4,
6,36,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText22,
NULL,
NULL,
3,
NULL
};
struct IntuiText IText23 = {
2,0,JAM1,
5,1,
NULL,
"DRFT",
NULL
};
struct Gadget Gadget2 = {
&Gadget3,
6,24,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText23,
NULL,
NULL,
2,
NULL
};
struct IntuiText IText24 = {
1,0,JAM1,
9,1,
&TOPAZ80,
"RST",
NULL
};
struct Gadget Gadget1 = {
&Gadget2,
6,12,
41,9,
NULL,
RELVERIFY+GADGIMMEDIATE+STRINGCENTER,
BOOLGADGET,
(APTR)&Border1,
NULL,
&IText24,
NULL,
NULL,
1,
NULL
};
struct Menu mymenu = {
NULL,
0,0,
0,0,
MENUENABLED,
(BYTE *)
"PrinterCTRL v1.00 (25.07.92) by Paul Miskovsky, Toronto, Canada.",
NULL
};
struct NewWindow mynewwin1 = {
NULL,NULL,
374,72,
0,1,
GADGETDOWN+GADGETUP+NEWPREFS+CLOSEWINDOW,
WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH,
&Gadget1,
NULL,
(UBYTE *)"Printer CTRL v1.00",
NULL,
NULL,
5,5,
-1,-1,
WBENCHSCREEN
};
// ---/ Main /--------------------------------------------------------------
void _main( cmdline )
char *cmdline;
{
struct IntuiMessage *imsg;
ULONG imsgClass;
UWORD imsgCode;
Open_All();
for(;;)
{
if((imsg = (struct IntuiMessage *)
GetMsg(mywin1->UserPort)) == 0L)
{
Wait(1L << mywin1->UserPort->mp_SigBit);
continue;
}
imsgClass = imsg->Class;
imsgCode = imsg->Code;
ReplyMsg((struct Message *) imsg);
switch(imsgClass)
{
case CLOSEWINDOW:
Close_All(0L, NULL);
break;
case MENUPICK:
if(MENUNUM(imsgCode) != MENUNULL)
Menu_Analysis(MENUNUM(imsgCode),
ITEMNUM(imsgCode),
SUBNUM(imsgCode));
break;
case GADGETUP:
GadgetIAddress = (struct Gadget *) imsg->IAddress;
Gadget_Analysis(GadgetIAddress->GadgetID);
break;
default:
break;
}
}
}
// ---/ Subroutines /-------------------------------------------------------
void Menu_Analysis(Menu, Item, SubItem)
SHORT Menu,Item,SubItem;
{
switch(Menu)
{
case 0:
switch(Item)
{
case 0:
Close_All(0L,NULL);
break;
default:
break;
}
default:
break;
}
}
void Gadget_Analysis( gadgetid )
USHORT gadgetid;
{
STRPTR temp="",code=" ";
UBYTE *longnum;
SHORT n=0;
if(!(ParallelError = OpenParallel()));
{
result = StatusParallel(ParallelIO,&status);
CloseParallel();
}
if(PrinterError = OpenPrinter(printerReq));
{
switch(gadgetid)
{
case EXIT:
ClosePrinter(printerReq);
Close_All(0L,NULL);
case LINE:
result = PrintPrtCommand(printerReq,aRIN,0,0,0,0);
strcpy(code,"aRIN");
break;
case HELP:
ReqShowText();
strcpy(code,"HELP");
break;
case CMD:
result = PrintPrtCommand(printerReq,(LONG)ReqGetLong(&getlong),0,0,0,0);
strcpy(code,"CMD#");
break;
case HEX:
result = NewReqGetString(&getnewstring);
longnum = (APTR)malloc(sizeof(char)*36);
while(numbers[n])
{
sprintf(longnum,"%s%c",longnum,(UBYTE)numbers[n++]);
}
result = PrintPrtESCCommand(printerReq,longnum);
strcpy(code,"ESC#");
free(longnum);
break;
case BELL:
result = PrintPrtESCCommand(printerReq,"\x07");
strcpy(code,"ESCx07");
break;
case SKIP:
result = PrintPrtCommand(printerReq,aPERF,0,0,0,0);
strcpy(code,"aPERF");
break;
case JUST:
result = PrintPrtCommand(printerReq,aJFY6,1,0,0,0);
strcpy(code,"aJFY6");
break;
case PROP:
result = PrintPrtCommand(printerReq,aPROP2,0,0,0,0);
strcpy(code,"aPROP2");
break;
case RLF:
result = PrintPrtCommand(printerReq,aRI,0,0,0,0);
strcpy(code,"aRI");
break;
case LF:
result = PrintPrtCommand(printerReq,aNEL,0,0,0,0);
strcpy(code,"aNEL");
break;
case TOF:
result = PrintPrtESCCommand(printerReq,"\x0C");
strcpy(code,"ESCx0C");
break;
case DOUB:
result = PrintPrtCommand(printerReq,aDEN4,0,0,0,0);
strcpy(code,"aDEN4");
break;
case SHAD:
result = PrintPrtCommand(printerReq,aDEN6,0,0,0,0);
strcpy(code,"aDEN6");
break;
case ENLRG:
result = PrintPrtCommand(printerReq,aSHORP6,0,0,0,0);
strcpy(code,"aSHORP6");
break;
case UNDER:
result = PrintPrtCommand(printerReq,aSGR4,0,0,0,0);
strcpy(code,"aSGR4");
break;
case ITAL:
result = PrintPrtCommand(printerReq,aSGR3,0,0,0,0);
strcpy(code,"aSGR3");
break;
case BOLD:
result = PrintPrtCommand(printerReq,aSGR1,0,0,0,0);
strcpy(code,"aSGR1");
break;
case FELITE:
result = PrintPrtCommand(printerReq,aSHORP2,0,0,0,0);
strcpy(code,"aSHORP2");
break;
case FPICA:
result = PrintPrtCommand(printerReq,aSHORP4,0,0,0,0);
strcpy(code,"aSHORP4");
break;
case FNORM:
result = PrintPrtCommand(printerReq,aSHORP0,0,0,0,0);
strcpy(code,"aSHORP0");
break;
case NLQ:
result = PrintPrtCommand(printerReq,aDEN2,0,0,0,0);
strcpy(code,"aDEN2");
break;
case DRFT:
result = PrintPrtCommand(printerReq,aSGR0,0,0,0,0);
strcpy(code,"aSGR0");
break;
case RST:
result = PrintPrtCommand(printerReq,aRIS,0,0,0,0);
strcpy(code,"aRIS");
break;
case STAT:
strcpy(code,"STATUS");
break;
case PRINT:
strcpy(temp,MakeFileRequester(&filereq));
result = PrintFile(printerReq,temp);
strcpy(code,"PRINT");
break;
default:
break;
}
ClosePrinter(printerReq);
}
temp = (char *)malloc(sizeof(char)*41);
if(result)
sprintf(temp,"%s - %s ERROR!",titlearray,code);
else
sprintf(temp,"%s - %s OK!",titlearray,code);
SetWindowTitles(mywin1,temp,(UBYTE *) ~0);
RefreshWindowFrame(mywin1);
free(temp);
}
void Open_All( void )
{
if(!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 33L)))
Close_All(20L, "\nRequires at least V33 Graphics.library\n");
if(!(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 33L)))
Close_All(20L, "\nRequires at least V33 Intuition.library\n");
if(!(ReqBase = (struct ReqLib *) OpenLibrary("req.library", 0L)))
Close_All(20L, "\nRequires at least V2.x req.library\n");
strcpy(mynewwin1.Title,GetNewWindowTitle());
CenterWindow( &mynewwin1 );
if(!(mywin1 = (struct Window *) OpenWindow(&mynewwin1)))
Close_All(20L, "\nCouldn't open window\n");
SetMenuStrip(mywin1,&mymenu);
rp = mywin1->RPort;
if(SetupPrinter() != NULL)
Close_All(20L, "\nCouldn't setup printer PORT\n");
if(SetUpParallel() != NULL)
Close_All(20L, "\nCouldn't setup parallel PORT\n");
if(!(ParallelError = OpenParallel()));
{
StatusParallel(ParallelIO,&status);
CloseParallel();
}
}
void Close_All( code,text )
LONG code;
STRPTR text;
{
// if(ParallelError == NULL) CloseDevice((struct IOReqest *) ParallelIO);
if(ParallelIO) DeleteExtIO((struct IORequest *) ParallelIO);
if(ParallelMP) DeletePort(ParallelMP);
// if(PrinterError == NULL) CloseDevice((struct IOReqest *) printerReq);
if(printerReq) DeletePrtReq(printerReq);
if(ReqBase != NULL) PurgeFiles(&filereq);
ClearMenuStrip(mywin1);
if(mywin1!= NULL) CloseWindow(mywin1);
if((IntuitionBase)!=NULL) CloseLibrary((struct Library *) IntuitionBase);
if((GfxBase)!=NULL) CloseLibrary((struct Library *) GfxBase);
if((ReqBase)!=NULL) CloseLibrary((struct Library *) ReqBase);
// if(text) SimpleRequest(text);
exit(code);
}
union printerIO *CreatePrtReq( void )
{
struct MsgPort *prtport;
union printerIO *request;
if(!(prtport = (struct MsgPort *) CreatePort("PrinterPORT",0)))
Close_All(20L, "\nUnable to Create Printer PORT\n");
if(!(request=(union printerIO *)
CreateExtIO(prtport,sizeof(union printerIO))))
{
DeletePort(prtport);
Close_All(20L, "\nUnable to create ExtIO on Printer PORT\n");
}
return(request);
}
LONG SetupPrinter( void )
{
printerReq = ((union printerIO *) CreatePrtReq());
return(0L);
}
void DeletePrtReq( request )
union printerIO *request;
{
struct MsgPort *prtport;
prtport = request->ios.io_Message.mn_ReplyPort;
DeleteExtIO((struct IORequest *) request);
DeletePort(prtport);
}
LONG OpenPrinter( request )
union printerIO *request;
{
if(PrinterError = (OpenDevice("printer.device",NULL,
(struct IORequest *) request, NULL)) != NULL)
{
textreq.Text = "Printer did not open!";
// textreq.Controls = NULL;
textreq.Window = mywin1;
textreq.NegativeText = "Abort";
textreq.Title = "Error!";
textreq.Timeout = 60;
textreq.versionnumber = REQVERSION;
textreq.blockcolor = 2;
result = TextRequest(&textreq);
return(1L);
}
else return(0L);
}
void ClosePrinter( request )
union printerIO *request;
{
if(PrinterError == NULL) CloseDevice((struct IOReqest *) printerReq);
}
LONG PrintPrtCommand( request, command, p0, p1, p2, p3 )
union printerIO *request;
LONG command;
UBYTE p0,p1,p2,p3;
{
request->iopc.io_Command = PRD_PRTCOMMAND;
request->iopc.io_PrtCommand = (UWORD)command;
request->iopc.io_Parm0 = p0;
request->iopc.io_Parm1 = p1;
request->iopc.io_Parm2 = p2;
request->iopc.io_Parm3 = p3;
return(LONG)(DoIO((struct IORequest *) request));
}
LONG PrintPrtESCCommand( request, buffer )
union printerIO *request;
UBYTE *buffer;
{
request->ios.io_Command = PRD_RAWWRITE;
request->ios.io_Data = (APTR)buffer;
request->ios.io_Length = strlen(buffer)+1;
return(LONG)(DoIO((struct IORequest *) request));
}
LONG PrintPrtRawString( request, buffer )
union printerIO *request;
STRPTR buffer;
{
request->ios.io_Command = PRD_RAWWRITE;
request->ios.io_Data = buffer;
request->ios.io_Length = strlen(buffer);
return(LONG)(DoIO((struct IORequest *) request));
}
LONG PrintDevCommand( request, devcommand )
union printerIO *request;
UWORD devcommand;
{
request->ios.io_Command = devcommand;
return(LONG)(DoIO((struct IORequest *) request));
}
UBYTE * GetNewWindowTitle( void )
{
struct Preferences *prefs, *prefsbuffer;
UBYTE type[5];
prefsbuffer = AllocMem((sizeof(struct Preferences)),MEMF_CHIP);
prefs = GetPrefs(prefsbuffer,sizeof(struct Preferences));
if( prefs->PrinterPort == PARALLEL_PRINTER ) strcpy(type,"PAR:");
else strcpy(type,"SER:");
sprintf(titlearray,"%s%s",type,prefs->PrinterFilename);
FreeMem(prefsbuffer,sizeof(struct Preferences));
return(titlearray);
}
void CenterWindow( pnewwin )
struct NewWindow *pnewwin;
{
pnewwin->LeftEdge =
((IntuitionBase->ActiveScreen->Width-pnewwin->Width)/2);
pnewwin->TopEdge =
((IntuitionBase->ActiveScreen->Height-pnewwin->Height)/2);
}
STRPTR MakeFileRequester( requester )
struct ReqFileRequester *requester;
{
char answerarray[DSIZE+FCHARS] = "";
char directoryname[DSIZE] = "";
char filename[FCHARS] = "";
answerarray[0] = 0;
requester->Title = "Select File to Print";
requester->PathName = answerarray;
requester->Dir = directoryname;
requester->File = filename;
strcpy(requester->Hide,"*.info");
strcpy(requester->Show,"*");
requester->Flags = FRQCACHINGM | FRQINFOGADGETM | FRQLOADINGM;
requester->dirnamescolor = 2;
requester->devicenamescolor = 2;
if(FileRequester( requester )) return(answerarray);
}
LONG ReqGetLong( getlongnum )
struct GetLongStruct *getlongnum;
{
getlongnum->titlebar = "Enter Driver CMD";
getlongnum->defaultval = NULL;
getlongnum->minlimit = NULL;
getlongnum->maxlimit = 255L;
getlongnum->window = NULL;
getlongnum->versionnumber = REQVERSION;
getlongnum->flags = NULL;
getlongnum->rfu2 = NULL;
if(GetLong(getlongnum)) return(getlongnum->result);
}
LONG NewReqGetString( getstring )
struct GetStringStruct *getstring;
{
STRPTR token,ptemp,stemp,res;
USHORT n=0;
result = 1L;
ptemp = (STRPTR)malloc(sizeof(char)*36);
stemp = (STRPTR)malloc(sizeof(char)*36);
getstring->titlebar = "Enter Code(s) in HEX";
getstring->stringbuffer = stemp;
getstring->window = NULL;
getstring->stringsize = 35;
getstring->visiblesize = 35;
getstring->versionnumber = REQVERSION;
getstring->flags = NULL;
getstring->rfu1 = NULL;
getstring->rfu2 = NULL;
getstring->rfu3 = NULL;
if(NewGetString(getstring))
{
strcpy(ptemp,getstring->stringbuffer);
result = 0L;
}
token = strtok(ptemp,", ");
numbers[n++] = strtol(token,&res,16);
while(token != NULL)
{
token = strtok(NULL,", ");
numbers[n++] = strtol(token,&res,16);
}
free(ptemp);
free(stemp);
return(result);
}
void ReqShowText( void )
{
SimpleRequest( "PrinterCTRL 1.00 (25.07.92) HELP\n\n"
" Read the original documentation for a \n"
" complete description of all functions \n"
" and features." );
}
LONG PrintFile( request, file )
union printerIO *request;
STRPTR file;
{
struct FileInfoBlock info;
APTR buffer;
BPTR fh1;
if((dfind(&info,file,0)) != NULL)
{
textreq.Text = " File was not found! ";
// textreq.Controls = control;
textreq.Window = NULL;
textreq.NegativeText = "Resume";
textreq.Title = "Error!";
textreq.Timeout = 5;
textreq.textcolor = 1;
textreq.detailcolor = 2;
textreq.blockcolor = 1;
textreq.versionnumber = REQVERSION;
result = TextRequest(&textreq);
return(1L);
}
if((fh1=(BPTR)Open(file,MODE_OLDFILE)) == NULL)
{
textreq.Text = " File could not be opened! ";
// textreq.Controls = control;
textreq.Window = NULL;
textreq.NegativeText = "Resume";
textreq.Title = "Error!";
textreq.Timeout = 5;
textreq.textcolor = 1;
textreq.detailcolor = 2;
textreq.blockcolor = 1;
textreq.versionnumber = REQVERSION;
result = TextRequest(&textreq);
return(1L);
}
if((buffer=AllocMem(info.fib_Size,MEMF_FAST|MEMF_CLEAR)) == NULL)
buffer=AllocMem(info.fib_Size,MEMF_CHIP|MEMF_CLEAR);
if(buffer == NULL)
{
textreq.Text = " Could not AllocMem required memory. ";
// textreq.Controls = control;
textreq.Window = NULL;
textreq.NegativeText = "Resume";
textreq.Title = "Error!";
textreq.Timeout = 5;
textreq.textcolor = 1;
textreq.detailcolor = 2;
textreq.blockcolor = 1;
textreq.versionnumber = REQVERSION;
result = TextRequest(&textreq);
return(1L);
}
if((Read((BPTR)fh1,buffer,info.fib_Size)) != NULL)
{
request->ios.io_Command = CMD_WRITE;
request->ios.io_Data = buffer;
request->ios.io_Length = info.fib_Size;
result = DoIO((struct IORequest *) request);
}
FreeMem(buffer,info.fib_Size);
Close((BPTR)fh1);
return(result);
}
LONG SetUpParallel( void )
{
if(ParallelMP=(struct MsgPort *)CreatePort(0,0))
{
if(ParallelIO=(struct IOExtPar *)
CreateExtIO(ParallelMP,sizeof(struct IOExtPar)))
{
ParallelIO->io_ParFlags = PARF_SHARED;
return(0L);
}
}
else return(1L);
}
LONG OpenParallel( void )
{
if(ParallelError = (OpenDevice(PARALLELNAME,UNIT_NUMBER,
(struct IORequest *) ParallelIO,0) != 0))
{
return(1L);
}
else return(0L);
}
void CloseParallel( void )
{
if(ParallelError == NULL) CloseDevice((struct IOReqest *) ParallelIO);
}
LONG StatusParallel( parallel, itext )
struct IOExtPar *parallel;
struct IntuiText *itext;
{
char text[45] = "";
int command;
command = parallel->IOPar.io_Command;
parallel->IOPar.io_Command = PDCMD_QUERY;
result = (DoIO((struct IORequest *)parallel));
strcpy(text," PAR:STATUS -");
if(parallel->io_Status & IOPTF_PARBUSY) strcat(text," BUSY");
else strcat(text," READY");
if(parallel->io_Status & IOPTF_PAPEROUT) strcat(text," NO_PAPER");
else strcat(text," PAPER_OK");
if(parallel->io_Status & IOPTF_PARSEL) strcat(text," ONLINE");
else strcat(text," OFFLINE");
if(command == CMD_READ) strcat(text," INPUT");
else strcat(text," OUTPUT");
parallel->IOPar.io_Command = command;
itext->FrontPen = 1;
itext->BackPen = 0;
itext->DrawMode = JAM2;
itext->ITextFont = &TOPAZ80;
itext->NextText = NULL;
itext->IText = (UBYTE *)text;
PrintIText(rp,itext,11L,49L);
return(result);
}
// ---/ End /---------------------------------------------------------------